package com.onpositive.gamemaker.rcp.environment;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.prefs.Preferences;

import org.eclipse.core.runtime.Platform;



public class WorkspaceLocation
{
	protected static Preferences  preferences = Preferences.userNodeForPackage(WorkspaceLocation.class); //TODO UserRoot
	
	protected static final String _KeyWorkspaceRootDir   = "wsRootDir";
	protected static final String _KeyRememberWorkspace  = "wsRemember";
	
	public static URL getWorkspaceURL()
    {
    	String path = preferences.get(_KeyWorkspaceRootDir, null);
    	if (path == null)
    		path = Platform.getInstallLocation().getURL().getPath();
		try
		{
			return new URL("file",null,path);
		} catch (MalformedURLException e)
		{
			e.printStackTrace();
		}
		return null;
    }
    
    public static void setWorkspaceURL(URL url)
    {
    	preferences.put(_KeyWorkspaceRootDir, url.getPath());
    }
}
